# _*_coding:utf-8 _*_
#@Time    :2019/3/27 12:56
#@Author  :Dapan
#@Email : 248312738@qq.com
# 数据库操作及配置文件
import pymysql


class GetMCode():
    def __init__(self):
        # 打开数据库连接
        self.db = pymysql.connect(
            host="47.99.158.176",
            port=3306,
            user="root",
            passwd="123456",
            db="yunfan_dev",
            charset='utf8')
        # 通过cursor方法获取操作游标
        self.cursor = self.db.cursor()
        # sql语句
        self.sql_shop_name = "SELECT w_id FROM tab_ztc_wangwang;"
        self.sql_version = "SELECT version FROM tab_reg_version WHERE soft_name='ZTCPlanDelete' AND status='1';"
        self.sql_tips = "SELECT msg FROM tab_reg_message WHERE status='1';"
        # 所有店铺名的列表
        self.shop_name_list = []

        self.tips_list = []

    def query_shop_names(self):
        self.cursor.execute(self.sql_shop_name)
        data2 = self.cursor.fetchall()  # fetch:获取
        # 输出结果集
        for i in data2:
            self.shop_name_list.append(i[0])
        return self.shop_name_list


    def query_version(self):
        # 执行sql语句
        self.cursor.execute(self.sql_version)
        # 使用fetchone方法获取一个查询结果集
        data = self.cursor.fetchall()  # fetch:获取
        version_code = data[0][0]
        return version_code



    def query_tips(self):
        self.cursor.execute(self.sql_tips)
        data3 = self.cursor.fetchall()  # fetch:获取
        # 输出结果集
        for i in data3:
            self.tips_list.append(i[0])
        return self.tips_list[0]


    def __del__(self):
        # 关闭数据库连接
        self.db.close()


if __name__ == '__main__':
    a = GetMCode()
    print(a.query_shop_names())
    print(a.query_version())
    print(a.query_tips())
